package it.uniroma1.nlp.cablegate;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class JaxP {

	/**
	 * @param args
	 * @throws ParserConfigurationException 
	 * @throws IOException 
	 * @throws SAXException 
	 */
	public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
		DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
		dbf.setNamespaceAware(true);
		
		
		DocumentBuilder db = dbf.newDocumentBuilder();
		File file = new File("./annotated/00HARARE5461.html.xml");
		Document doc = db.parse(file);

		Element element = doc.getDocumentElement();
		
		System.out.println(element.getChildNodes());
		
		NodeList nList = doc.getElementsByTagName("token");
		System.out.println(nList.getLength());
		
		Node token;
		
		for(int i=0 ; i<nList.getLength(); i++){
			token = nList.item(i);
			//System.out.println(token.getTextContent());
			
			NodeList tokenChildren = token.getChildNodes();
			for(int j=0; j<tokenChildren.getLength(); j++){
				Node tokenChild = tokenChildren.item(j);
				if(tokenChild.getNodeName().equals("NER") && 
						tokenChild.getTextContent().equals("LOCATION")){
					System.out.println(token.getTextContent());
				}
			}
		}
	}

}
